package practise.service.impl;

//账户业务层实现类

import com.sun.javaws.IconUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import practise.dao.IAccountDao;
import practise.daomain.Account;
import practise.service.IAccountService;

import java.util.List;

@Service("accountService")
public class AccountServiceImpl implements IAccountService {

    @Autowired
    private IAccountDao accountDao;

    public List<Account> findAllAccount() {
        return accountDao.findAllAccount();
    }

    public Account findAccountById(Integer accountId) {
        return accountDao.findAccountById(accountId);
    }

    public void saveAccount(Account account) {
        accountDao.saveAccount(account);
    }

    public void updateAccount(Account account) {
        accountDao.updateAccount(account);
    }

    public void deleteAccount(Integer accountId) {
        accountDao.deleteAccount(accountId);
    }

    public void transfer(String sourceName, String targetName, Float money) {
        System.out.println("开始转钱了。。。");
        //转出账户
        Account source = accountDao.findAccountByName(sourceName);
        //转入账户
        Account target = accountDao.findAccountByName(targetName);
        //减钱
        source.setMoney(source.getMoney()-money);
        int i=1/0;
        //加钱
        target.setMoney(target.getMoney()+money);
        //更新
        accountDao.updateAccount(source);
        accountDao.updateAccount(target);
    }
}
